<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title><?php echo $GLOBALS['project']['name']; ?> Download</title>
    <!-- Required Koi Libs -->
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/mootools/1.11/mootools-yui-compressed.js"></script>
    <script type="text/javascript" src="?f=koi.js"></script>
    <link rel="stylesheet" href="?f=koi.css" type="text/css" />
    <!-- Koi End -->
    
    <script type="text/javascript" src="?f=design.js"></script>
    <link rel="stylesheet" href="?f=design.css" type="text/css" />
</head>
<body>
<?php
    // Required Koi lib
    koi_import('koi.php');
?>
    
    <div id="mainbox">
        <div id="progresstabs">
            <p id="downloadtab" class="queue"><img src="?f=download.png" alt="" />Download</p>
            <p id="scantab" class="queue"><img src="?f=scan.png" alt="" />Scan</p>
            <p id="installtab" class="queue"><img src="?f=install.png" alt="" />Install</p>
            <p id="cleanuptab" class="queue"><img src="?f=cleanup.png" alt="" />Cleanup</p>
        </div>
        
        <div id="maincontent">
            <h1><?php echo $GLOBALS['project']['name']; ?></h1>
            
            <div id="slides">
                <noscript>
                    <h2 class="bad">Javascript is not enabled!</h2>
                    <p>This installer requires javascript in order to run through.</p>
                    <p>Please enable javascript in your browser and click refresh to re-start the installation</p>
                </noscript>
                
                <div id="downloaderror">
                    <h2 class="bad">Download Error</h2>
                    <p>Koi could not download the package files required to install <?php echo $GLOBALS['project']['name']; ?>. You will need to download the .tar files manually and upload them to this folder.</p>
                    <input type="button" class="button" onclick="location.reload();" value="Refresh" />
                </div>
                
                <div id="introbox">
<?php
// Got any errors?
switch ($status) {
    case 'write': ?>
                    <h2 class="bad">Permission Error</h2>
                    <p>PHP does not have permission to write files to this folder. You should be able to fix this issue by CHMODing this folder to 766, 666 or similar.</p>
                    <input type="button" class="button" onclick="location.reload();" value="Refresh" />
<?php break;
    
    case 'lock': ?>
                    <h2 class="bad">Installation Locked</h2>
                    <p>For security purposes this installation has been locked to the IP address of the first visitor. To re-gain access FTP to this folder and delete lock.php</p>
                    <input type="button" class="button" onclick="location.reload();" value="Refresh" />
<?php break;
    
    case 'good':
        if (is_file('./lib/lib.php')) {$upgrade = true;
            define('supress',true);
            require_once('./lib/lib.php');
            if (!get_config('basepath')) { ?>
                    <h2 class="bad">Bad Upgrade</h2>
                    <p>Your current <?php echo $GLOBALS['project']['name']; ?> installation has not been properly configured, have you even installed it yet? Upgrade cannot continue.</p>
<?php       }
            if (array_search(get_config('version'),array('0.1.5b','0.1.7b'))!==false) { ?>
                    <h2>Ready to Upgrade</h2>
                    <p>Welcome to the <?php echo $GLOBALS['project']['name']; ?> upgrader.</p>
                    <p>All initial tests were sucessful. Click the button below to begin the automated setup.</p>
                    <input type="button" class="button" onclick="koi_start();" value="Start Upgrade" />
                    <script type="text/javascript">koi_action = 'upgrade'; (function(){koi_alert("<h2>Upgrade Warning</h2><p>This is a major update to the ComicCMS system and is going to take a while. Your comics, news posts and users will be converted automatically but templates will need to be tweaked manually. Please set aside 30 minutes to go through the upgrade process properly.</p><p>MOST IMPORTANTLY: Back up your files by downloading the folder called \"storage\" through FTP before continuing!</p>");}).delay(100);</script>
<?php       } else { ?>
                    <h2 class="bad">Bad Upgrade</h2>
                    <p>The version of your current <?php echo $GLOBALS['project']['name']; ?> installation is no longer supported by this upgrade method. Please visit the <a href="http://comiccms.com/">ComicCMS.com</a> website for alternative instructions.</p>
<?php       } ?>
<?php   } else { $upgrade = false; ?>
                    <h2>Ready to Install</h2>
                    <p>Welcome to the <?php echo $GLOBALS['project']['name']; ?> installer.</p>
                    <?php
            $bad = false;
            $dirlist = opendir('./');
            while( ($file = readdir($dirlist)) !== false) {
                if ( (!is_dir($file)) && ($file != 'download.php') && ($file != 'lock.php') && (!strpos($file,'.tar')) && (!strpos($file,'.lst')) ) $bad=true;
            }
            if ($bad) { ?>
                    <p>WARNING: This directory is not empty! The installer will overwrite anything in it's path.</p>
<?php       } else { ?>
                    <p>All initial tests were sucessful. Click the button below to begin the automated setup.</p>
<?php       } ?>
                    <input type="button" class="button" onclick="koi_start();" value="Start Installation" />
<?php   }
        break;
}
?>
                </div>
                
                <div id="progressbox">
                    <img src="?f=slide.jpg" alt="Koi" />
                </div>
                
                <div id="endbox">
                    <h2>Installation Complete</h2>
                    <p>Everything has been downloaded and installed.</p>
                    <p>You can now go on to configure <?php echo $GLOBALS['project']['name']; ?>.</p>
                    <input type="button" class="button" onclick="window.location = '<?php echo ($upgrade?'upgrade/':$GLOBALS['project']['continue']); ?>';" value="Proceed" />
                </div>
            </div>
            
            <div id="progressbar">
                <div id="progressnote"><span id="progressstatus"></span></div>
                <div id="progressback"></div>
                <div id="progresswidth" style="width:0%;"></div>
            </div>
        </div>
    </div>
    
    <!-- Alert messages -->
    <div id="alert">
        <div id="alertmsg">
            <div></div>
            <input type="button" id="alertok" onclick="alert_close();" value="Ok" />
        </div>
    </div>
</body>
</html>